﻿@model LastoRevival.Service.Contracts.Models.ViewForumAccessModel

@using LastoRevival.Service.Contracts.Models;
@using LastoRevival.Website;

@{ 
	ViewBag.Title = "Set Forum Access Permissions";

	this.AddIndexBreadCrumb();
	this.AddForumBreadCrumb(Model.ForumID);
	this.AddCurrentBreadCrumb("Set Permissions");
}


<script type="text/javascript">

	function showSaveButton(id)
	{
		$("#saveChange-" + id).show();
	}

	function hideSaveButton(id)
	{
		$("#saveChange-" + id).hide();
	}

	function saveChange(id)
	{
		$.ajax(
		{
			type: "POST",
			url: "@Url.Action("EditForumAccess", "Admin", new { forumID = Model.ForumID })",
			data:
			{
				"ForumID" : "@Model.ForumID",
				"GroupID" : id,
				"Access" : $("#access-" + id).val()
			},
			beforeSend: blockUI,
			error: showAjaxException,
			complete: unblockUI,
			success: function(data)
			{
				if (data == true)
				{
					hideSaveButton(id);
					alert("Permissions updated");
				}
				else
				{
					alert("Unable to update permissions");
				}
			}
		});
	}

</script>

<h1>@ViewBag.Title</h1>

<table id="group-access-list" style="">
	<thead>
		<tr>
			<td style="font-weight: bold; padding: 0.5em;">Group Name</td>
			<td style="font-weight: bold; padding: 0.5em;">Access</td>
			<td style="padding: 0.5em;"></td>
		</tr>
	</thead>
	<tbody>
		@foreach (var item in Model.Groups)
		{
			<tr>
				<td style="padding: 0.5em;">@item.GroupName</td>
				<td style="padding: 0.5em;">
					<select id="access-@item.GroupID" onchange="showSaveButton(@item.GroupID);">
						
						@foreach (var type in new ForumAccessType().GetAllValues())
						{
							var value = (int)type;
							var selected = type == item.AccessType ? "selected='selected'" : "";
							<option value="@value" @selected>@type</option>
						}
					
					</select>

				</td>
				<td style="padding: 0.5em;">
					<button type="button" id="saveChange-@item.GroupID" onclick="saveChange(@item.GroupID);" style="display: none">Save</button>
				</td>
			</tr>
		}
	</tbody>
</table>

